import {UserActions} from './user';

const initialState = {
  role: '',
};

export const RegisterActions = {
  REGISTER_FORM_UPDATE: 'register_form_update',
  REGISTER_FORM_RESET: 'register_form_reset',
};

export function updateRegisterForm(payload) {
  return {
    type: RegisterActions.REGISTER_FORM_UPDATE,
    payload,
  };
}

export function resetRegisterForm() {
  return {
    type: RegisterActions.REGISTER_FORM_RESET,
  };
}

export default function registerForm(state = initialState, action) {
  switch (action.type) {
    case RegisterActions.REGISTER_FORM_UPDATE:
      return {...state, ...action.payload};
    case RegisterActions.REGISTER_FORM_RESET:
      return {};
    case UserActions.USER_SIGN_OUT:
      return {
        role: '',
      };
    default:
      return state;
  }
}
